<template>
  <el-container class="app-container">
    <el-aside>
      <div class="system-title">智能排班系统</div>
      <el-menu
        router
        :default-active="$route.path"
        class="el-menu-vertical"
        :collapse="isCollapse"
      >
        <el-menu-item index="/schedule">
          <el-icon><Calendar /></el-icon>
          <span>排班管理</span>
        </el-menu-item>
        <el-menu-item index="/calendar">
          <el-icon><Calendar /></el-icon>
          <span>班次日历</span>
        </el-menu-item>
        <el-menu-item index="/employees">
          <el-icon><User /></el-icon>
          <span>员工管理</span>
        </el-menu-item>
        <el-menu-item index="/shifts">
          <el-icon><Clock /></el-icon>
          <span>班次管理</span>
        </el-menu-item>
        <el-menu-item index="/products">
          <el-icon><Goods /></el-icon>
          <span>产品管理</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-main>
      <router-view></router-view>
    </el-main>
  </el-container>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { Calendar, User, Clock, Goods } from '@element-plus/icons-vue'

const isCollapse = ref(false)
const MIN_WIDTH = 768

const handleResize = () => {
  isCollapse.value = window.innerWidth <= MIN_WIDTH
}

onMounted(() => {
  handleResize()
  window.addEventListener('resize', handleResize)
})

onUnmounted(() => {
  window.removeEventListener('resize', handleResize)
})
</script>

<style scoped>
.app-container {
  height: 100vh;
  display: flex;
  overflow: hidden;
}

.el-aside {
  padding-top: 0;
  width: auto;
  transition: all 0.3s;
  background-color: var(--apple-sidebar-bg);
  border-right: 1px solid var(--apple-border-color);
  box-shadow: var(--apple-shadow-sm);
}

.system-title {
  padding: var(--apple-spacing-md) var(--apple-spacing-lg);
  font-size: 18px;
  font-weight: bold;
  color: var(--apple-primary-color);
  text-align: center;
  border-bottom: 1px solid var(--apple-border-color);
  margin-bottom: var(--apple-spacing-md);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.el-menu-vertical {
  height: calc(100% - 60px);
  padding: var(--apple-spacing-md);
  border-right: none;
}

.el-menu-vertical:not(.el-menu--collapse) {
  width: 200px;
}

.el-menu-item {
  margin: var(--apple-spacing-xs) 0;
  border-radius: var(--apple-radius-md);
  height: 44px;
  line-height: 44px;
  padding-left: var(--apple-spacing-md) !important;
}

.el-menu-item .el-icon {
  margin-right: var(--apple-spacing-md);
  font-size: 18px;
}

.el-main {
  padding: var(--apple-spacing-xl);
  overflow-y: auto;
  flex: 1;
  min-width: 0;
  background-color: var(--apple-bg-color);
}

@media (max-width: 1024px) {
  .el-main {
    padding: var(--apple-spacing-lg);
  }
}

@media (max-width: 768px) {
  .el-main {
    padding: var(--apple-spacing-md);
  }

  .el-menu-item .el-icon {
    margin-right: 0;
  }
}
</style>
